<?php

namespace app\admin\model\litestore;

use think\Model;


class Freight extends Model
{

    

    

    // 表名
    protected $name = 'litestore_freight';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'method_text',
        'free_shipping_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    
    public function getMethodList()
    {
        return ['10' => __('Method 10'), '20' => __('Method 20')];
    }

    public function getFreeShippingList()
    {
        return ['0' => __('Free_shipping 0'), '1' => __('Free_shipping 1')];
    }


    public function getMethodTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['method']) ? $data['method'] : '');
        $list = $this->getMethodList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getFreeShippingTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['free_shipping']) ? $data['free_shipping'] : '');
        $list = $this->getFreeShippingList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
